﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>积分兑换记录</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link href="../demo.css" rel="stylesheet" type="text/css" />
<script src="../../scripts/boot.js" type="text/javascript"></script>
<style type="text/css">
html,body {
	width: 100%;
	height: 100%;
	border: 0;
	margin: 0;
	padding: 0;
	overflow: visible;
}
</style>
</head>
<body>
	<div class="mini-toolbar" style="padding: 2px; border: 0;">
		<table style="width: 100%;">
			<tr>
				<td style="width: 100%;"><a class="mini-button"
					iconCls="icon-add" onclick="success()" plain="true">兑换成功</a> <a
					class="mini-button" iconCls="icon-add" onclick="error()"
					plain="true">兑换失败</a> <!--<a class="mini-button" iconCls="icon-remove" onclick="" plain="true">删除</a>-->
					<a class="mini-button" iconCls="icon-download"
					onclick="downloadData()" plain="true">数据下载</a></td>
				<td style="white-space: nowrap;"><label
					style="font-family: Verdana;"> 类型: </label> <input id="typestr"
					class="mini-combobox" data="types" /> <label
					style="font-family: Verdana;"> 时间: </label> <input id="datebegin"
					class="mini-datepicker" format="yyyy-MM-dd HH" timeFormat="HH"
					showTime="true" />~<input id="dateend" class="mini-datepicker"
					format="yyyy-MM-dd HH" timeFormat="HH" showTime="true" /> <label
					style="font-family: Verdana;"> 兑换结果: </label> <input id="states"
					class="mini-combobox" data="states" /> <!--<label style="font-family:Verdana;"> 类型: </label>
                <input name="type" class="mini-combobox" style="width: 100px;"  data="Genders"/>-->
					<label style="font-family: Verdana;">用户ID:</label> <input
					id="username" class="mini-textbox" /> <label
					style="font-family: Verdana;">兑换账户:</label> <input id="accountstr"
					class="mini-textbox" /> <a class="mini-button"
					iconCls="icon-search" plain="true" onclick="search();">查询</a></td>
			</tr>
			<tr>
				<td colspan="2" style="width: 100%;" align="center"><label
					style="font-family: Verdana;">兑换中: </label> <label
					style="font-family: Verdana;" id="num1">0 </label>&nbsp;&nbsp; <label
					style="font-family: Verdana;"> 兑换成功: </label> <label
					style="font-family: Verdana;" id="num2">0 </label>&nbsp;&nbsp; <label
					style="font-family: Verdana;"> 兑换失败: </label> <label
					style="font-family: Verdana;" id="num3">0 </label></td>
			</tr>
		</table>
	</div>
	<!--撑满页面-->
	<div class="mini-fit" style="height: 100px;">
		<div id="datagrid1" class="mini-datagrid"
			style="width: 100%; height: 100%;"
			url="/ios/pages/CreditsExchange/list.do" idField="id"
			onpreload="init()" sizeList="[5,10,20,50]" allowResize="true"
			pageSize="10" allowCellSelect="true" multiSelect="true">
			<div property="columns">
				<div type="checkcolumn" style="width: 5px;"></div>
				<div type="indexcolumn" style="width: 5px;"></div>
				<div field="userid" headerAlign="center" allowSort="true">用户ID</div>
				<div field="username" headerAlign="center" allowSort="true">用户昵称</div>
				<div field="typeStr" headerAlign="center">类型</div>
				<div field="crdate" allowSort="true" align="center"
					headerAlign="center">时间</div>
				<div field="integral" allowSort="true">积分</div>
				<div field="money" headerAlign="center" allowSort="true">金额</div>
				<div field="account" headerAlign="center" allowSort="true">兑换账户</div>
				<div field=isBlack headerAlign="center" allowSort="true"
					renderer="onIsBlackRenderer">是否在黑名单</div>
				<div field="state" headerAlign="center" allowSort="true"
					renderer="onStateRenderer">兑换结果</div>
				<div field=isCheck headerAlign="center" allowSort="true" 
					renderer="onIsCheckRenderer">是否通过规则</div>
				<div field="reason" headerAlign="center" allowSort="true"
				renderer="onTitleRenderer"	>没通过原因</div>
				<div field="id" headerAlign="center" renderer="onHandleRenderer"
					width="120">操作</div>
				<div field="remark" headerAlign="center" allowSort="true">备注</div>
				<div field="operTime" headerAlign="center" allowSort="true">操作时间</div>
				<div field="IP" headerAlign="center" allowSort="true">IP</div>
				<div field="version" headerAlign="center" allowSort="true">版本号</div>
			</div>
		</div>
	</div>
	<!--添加和编辑页面-->
	<div id="editWindow" class="mini-window" title="填写失败原因"
		style="width: 400px; height: 154px; display: none;" showModal="true"
		allowResize="true" iconCls="icon-save" allowDrag="true">
		<input class="mini-hidden" name="id" id="id" />
		<div id="editform" class="form">
			<a class="mini-button" onclick="setData('未实名')" plain="true">未实名</a>
			<a class="mini-button" onclick="setData('账号错误')" plain="true">账号错误</a>
			<a class="mini-button" onclick="setData('黑名单')" plain="true">黑名单</a>
			<textarea class="mini-textarea" name="remark" id="note"
				style="width: 100%; height: 80%" emptyText="请输入备注"></textarea>
			<div align="right" style="padding: 10px">
				<a class="mini-button" iconCls="icon-save"
					href="javascript:saveRow()">保存</a> <a class="mini-button"
					iconCls="icon-close" href="javascript:cancelRow()">关闭</a>
			</div>
		</div>
	</div>

	<script type="text/javascript">
		var states = [ {
			id : '',
			text : '全部'
		}, {
			id : 1,
			text : '兑换中'
		}, {
			id : 2,
			text : '兑换成功'
		}, {
			id : 3,
			text : '兑换失败'
		} ];
		var isBlacks = [ {
			id : 0,
			text : '否'
		}, {
			id : 1,
			text : '是'
		} ];
		var isChecks = [ {
			id : 0,
			text : '是'
		}, {
			id : 1,
			text : '否'
		} ];
		
		var types = [ {
			id : '',
			text : '全部'
		}, {
			id : '支付宝',
			text : '支付宝'
		}, {
			id : '财付通',
			text : '财付通'
		}, {
			id : 'Q币',
			text : 'Q币'
		}, {
			id : '话费',
			text : '话费'
		} ];
		
		var titles = [ {
			id : '',
			text : ''
		}, {
			id : '未通过规则A',
			text : 'A、检查兑换账号是否在黑名单（黑名单不通过'
		}, {
			id : '未通过规则B',
			text : 'B、检查该兑换账号对应的ID名下是否曾经有黑名单兑换账号。'
		},  {
			id : '未通过规则C',
			text : 'C、兑换申请是否重复，重复的不通过（目前有遇到的情况就是同一个ID，同1秒有多个相同的兑换请求，实际上是只有一次兑换申请，由于网络卡或者其他的原因，导致重复的兑换请求'
		},{
			id : '未通过规则D',
			text : 'D、检索该兑换账号对应的ID，24小时内，同一个积分渠道（包含填写上级推荐代码获取的20分）获取相同积分的个数是否超过X个（X可配置）（超过不通过）'
		},  {
			id : '未通过规则E',
			text : 'E、检索该兑换账号对应的ID是否有上级，如果有，检索是否和上级是同一个IP段。（同IP段不通过,IP段指AA:BB：00:00中的AA:BB段）'
		}, {
			id : '未通过规则F',
			text : 'F、检索该兑换账号对应的ID是否有上级，如果有，检索是否和上级使用相同的兑换账号。（如果相同不通过----无论支付宝、财付通、Q号，只要曾经使用过的都匹配）如果上级的下线数大于等于4个时，才不通过'
		}, {
			id : '未通过规则G',
			text : 'G、检索该兑换账号对应的ID是否有下级，如果有，检索是否和下级（有多个下级的，检索最近的5个）是同一个IP段。（同IP段不通过,IP段指AA:BB：00:00中的AA:BB段）'
		},{
			id : '未通过规则H',
			text : '检索该兑换账号对应的ID是否有下级，如果有，检索是否和下级（有多个下级的，检索最近的10个）使用相同的兑换账号。（如果相同不通过----无论支付宝、财付通、Q号，只要曾经使用过的都匹配）如果下级使用的兑换账号大于等于4个时，才不通过'
		} ];


		function onStateRenderer(e) {
			var record = e.record;
			for (var i = 0, l = states.length; i < l; i++) {
				var g = states[i];
				if (g.id == e.value) {
					var num = document.getElementById('num' + g.id).innerText;
					num = parseInt(num) + record.money;
					document.getElementById('num' + g.id).innerText = num;
					return g.text;
				}
			}
			return "";
		}

		function onIsBlackRenderer(e) {
			var record = e.record;
			for (var i = 0, l = isBlacks.length; i < l; i++) {
				var g = isBlacks[i];
				if (g.id == e.value) {
					return g.text;
				}
			}
			return "";
		}

		function onIsCheckRenderer(e) {
			var record = e.record;
			for (var i = 0, l = isChecks.length; i < l; i++) {
				var g = isChecks[i];
				if (g.id == e.value) {
					return g.text;
				}
			}
			return "";
		}
		
		function onTitleRenderer(e) {
			var record = e.record;
			var s='';
			for (var i = 0, l = titles.length; i < l; i++) {
				var g = titles[i];
				if (g.id == e.value) {
					s=s+'&nbsp;&nbsp;<a title='+g.text+' >'+e.value+'</a>';
					return s;
				}
			}
			return "";
		}
		
		function onHandleRenderer(e) {
			var grid = e.sender;
			var record = e.record;
			var id = record.id;
			var state = record.state;
			var s = '';
			if (state == '1') {
				s = s
						+ '&nbsp;&nbsp;<a class="New_Button" href="javascript:onClickSuccess(\''
						+ id + '\');">兑换成功</a>';
				s = s
						+ '&nbsp;&nbsp;<a class="New_Button" href="javascript:onClickError(\''
						+ id + '\');">兑换失败</a>';
			}
			return s;
		}

		mini.parse();
		var grid = mini.get("datagrid1");
		var form = new mini.Form("#editform");
		var editWindow = mini.get("#editWindow");
		grid.load();

		function onClickSuccess(id) {
			mini.confirm("您确定兑换成功？", "确定？", function(action, value) {
				if (action == "ok") {
					myajax(id + ",", "0");
				} else {
					return;
				}
			}, true);
		}

		function onClickError(id) {
			editWindow.show();
			form.clear();
			//   form.loading();
			mini.get("id").setValue(id);
			/*   mini.confirm("您确定兑换失败？", "确定？",
			       function (action, value) {            
			           if (action == "ok") {
			               myajax(id+",","1");
			          }else{
			             return;
			          }
			   },true);*/
		}

		function myajax(id, type) {
			var messageid = mini.loading("正在执行...", "wait");
			$.ajax({
				url : "/ios/pages/CreditsExchange/update.do?id=" + id
						+ "&type=" + type,
				success : function(text) {
					var o = mini.decode(text);
					mini.hideMessageBox(messageid);
					if (o.state) {
						grid.load();
					} else {
						mini.alert("删除出错");
					}
				},
				error : function() {
					mini.hideMessageBox(messageid);
					mini.alert("删除出错");
				}
			});
		}

		function success() {
			var rows = grid.getSelecteds();
			var ids = "";
			for (i = 0; i < rows.length; i++) {
				ids += rows[i].id + ",";
			}
			mini.confirm("你确定兑换成功吗？", "确定？", function(action, value) {
				if (action == "ok") {
					if (rows.length > 0) {
						myajax(ids, "0");
					} else {
						return;
					}
				} else {
					return;
				}
			}, true);
		}

		function error() {
			var rows = grid.getSelecteds();
			var ids = "";
			for (i = 0; i < rows.length; i++) {
				ids += rows[i].id + ",";
			}
			/*	mini.confirm("你确定兑换失败吗？", "确定？",
			       function (action, value) {            
			           if (action == "ok") {
			                if (rows.length>0) {
			                  myajax(ids,"1");
			               } else {
			                   return;
			           	}
			          }else{
			             return;
			          }
			   },true);*/
			editWindow.show();
			form.clear();
			//   form.loading();
			mini.get("id").setValue(ids);
		}

		function search() {
			var datebegin = mini.get("datebegin").getFormValue();
			var dateend = mini.get("dateend").getFormValue();
			var states = mini.get("states").getValue();
			var username = mini.get("username").getValue();
			var typestr = mini.get("typestr").getValue();
			var accountstr = mini.get("accountstr").getValue();
			grid.load({
				userid : username,
				crdatebegin : datebegin,
				crdateend : dateend,
				state : states,
				typeStr : typestr,
				account : accountstr
			});
			grid.clearSelect();
		}

		function downloadData() {
			var datebegin = mini.get("datebegin").getFormValue();
			var dateend = mini.get("dateend").getFormValue();
			var states = mini.get("states").getValue();
			var username = mini.get("username").getValue();
			var typestr = mini.get("typestr").getValue();
			var accountstr = mini.get("accountstr").getValue();
			var url = "/ios/pages/CreditsExchange/exportData.do?userid="
					+ username + "&crdatebegin=" + datebegin + "&crdateend="
					+ dateend + "&state=" + states + "&typeStr=" + typestr
					+ "&account=" + accountstr;
			window.location.href = url;
		}

		function setData(data) {
			mini.get("note").setValue(data);
		}

		function saveRow() {
			form.validate();
			if (form.isValid() == false)
				return;
			var data = form.getData();
			var json = mini.encode(data);
			form.loading();
			var id = mini.get("id").getValue(id);
			$.ajax({
				url : "updateRemark.do?id=" + id,
				type : "post",
				data : {
					submitData : json
				},
				success : function(text) {
					var o = mini.decode(text);
					if (o.state) {
						form.unmask();
						grid.load();
						editWindow.hide();
					} else {
						form.unmask();
						alert("保存出错了!");
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert("请求出错了!");
				}
			});
		}

		function cancelRow() {
			editWindow.hide();
		}

		function init() {
			document.getElementById('num1').innerText = 0;
			document.getElementById('num2').innerText = 0;
			document.getElementById('num3').innerText = 0;
		}
	</script>
</body>
</html>